package automat;

/**
 * @author: Alexander Martyushov
 */
public class GumballMachine {

    final static int SOLD_OUT = 0;
    final static int NO_QUARTER = 1;
    final static int HAS_QUARTER = 2;
    final static int SOLD = 3;

    int state = SOLD_OUT;
    int count = 0;

    public GumballMachine(int count){
        this.count = count;
        if (count>0){
            state = NO_QUARTER;
        }
    }

    public void insertQuarter(){
        if (state == HAS_QUARTER){
            System.out.println("you cannot insert another quarter");
        } else if (state == NO_QUARTER){
            state = HAS_QUARTER;
            System.out.println("you inserted quarter");
        } else if (state == SOLD_OUT){
            System.out.println("the machine is empty");
        } else if (state == SOLD){
            System.out.println("wait you are already giving a gumball");
        }
    }

    public void ejectQuarter(){
        if (state == HAS_QUARTER){
            System.out.println("quarter returned");
            state = NO_QUARTER;
        } else if (state == NO_QUARTER){
            System.out.println("you have no inserted quarter");
        } else if (state == SOLD_OUT){
            System.out.println("you have no inserted quarter");
        } else if (state == SOLD){
            System.out.println("");
        }
    }
}
